﻿#include "tftp.h"
#include "utils.h"

//#include <netinet/in.h>
//#include <qcstring.h>
#include <winsock.h>

namespace TFTP {
void TransferInfo::sendError(ErrorCode ec, const QString &errMsg)
{
    QByteArray dgram;
    dgram.resize(errMsg.length() + 5);
	wordOfArray(dgram)[0] = htons( (quint16 )ERROR );
	wordOfArray(dgram)[1] = htons( (quint16 )ec );
	
//	memcpy( dgram.data() + 4, errMsg.ascii(), errMsg.length()+1 );
    memcpy( dgram.data() + 4, errMsg.data(), errMsg.length()+1 );

    if( sd->writeDatagram(dgram.data(), dgram.size(), dAddr, dPort) == -1 )
        qWarning( "发送错误数据包   %d", sd->error() );
}

};
